class Solution(object):
    def threeSum(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        result = []
        m = {}
        m_r = {}
        nums_len = len(nums)
        for i in range(0, nums_len):
            if nums[i] not in m:
                m[nums[i]] = []
            m[nums[i]].append(i)
        for i in range(0, nums_len):
            for j in range(i+1, nums_len):
                l = 0 - (nums[i] + nums[j])
                if l in m:
                    t = tuple(sorted([nums[i], nums[j], l]))
                    if t in m_r:
                        continue
                    m_r[t] = 1
                    for k in m[l]:
                        if k != i and k != j:
                            result.append([nums[i], nums[j], nums[k]])
                            break
        return result

s = Solution()
nums = [-1,0,1,2,-1,-4]
result = s.threeSum(nums)
print(result)

nums = [0,1,1]
result = s.threeSum(nums)
print(result)

nums = [0,0,0]
result = s.threeSum(nums)
print(result)
